<?php
namespace api\user\controller;

use api\user\model\TaskModel;
use api\common\controller\RestUserBaseController;
use think\Db;

class TaskController extends RestUserBaseController
{
    protected $TaskModel;

    public function __construct()
    {
        parent::__construct();
        $this->userId = $this->getUserId();
        $this->TaskModel = new TaskModel();
    }


    public function index()
    {
        $param          = $this->request->param();
        $param['where'] = [
            'status' => 1
        ];
        $param['order'] = '+id';
        $data = $this->TaskModel
        ->getDatas($param)
        ->each(function($item, $key){
            $id = Db::name('user_task')
            ->where(['task_id'=>$item['id'],'user_id'=>$this->userId])
            ->value('id');
            $item['finsh'] = $id>0?1:0;
            return $item;
        });
        $this->success('请求成功', ['list' => $data]);
    }

}
